home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / utility / ffe101.zip / GRAPH.SWG / 0026_DXF.pas < prev   
Pascal/Delphi Source File  |  1997-02-15  |  64KB  |  1,399 lines

  1. [ This file is an excerpt from the AutoCAD Release 10 Reference Manual.
  2.   Copyright (C) 1988 Autodesk, Inc.  All rights reserved. ]
  3.  
  4.                                Appendix C
  5.                    Drawing Interchange and File Formats
  6.  
  7.  
  8. AutoCAD  can  be  used by itself as  a  complete drawing editor. In some
  9. appli- cations, however, other programs must examine drawings created by
  10. AutoCAD  or  generate drawings to be  viewed,  modified, or plotted with
  11. AutoCAD.
  12.  
  13. For example, if you've made an architectural drawing with AutoCAD, using
  14. INSERTed  parts to represent windows, doors,  and so on, you can process
  15. the  drawing file and produce a bill  of materials of all the items used
  16. in  the drawing, or even make energy  use calculations based on the area
  17. and the number and type of windows used. Another possible application is
  18. to  use  AutoCAD  to describe structures that  are  then sent to a large
  19. computer  for  finite  element  structural  analysis.  You  can  compute
  20. stresses  and  displace- ments and send  back information to display the
  21. deformed structure as an AutoCAD drawing.
  22.  
  23. Since  the  AutoCAD  drawing database (.dwg  file)  is written in a very
  24. compact  format  that  changes significantly from  time  to  time as new
  25. features  are added, we do not document  its format and do not recommend
  26. that  you  attempt to write programs to  read  it directly. To assist in
  27. interchanging  drawings  between AutoCAD and  other programs, a "Drawing
  28. Interchange" file format (DXF(tm)) has been defined. All implementations
  29. of  AutoCAD  accept this format and are  able  to convert it to and from
  30. their internal drawing file representation.
  31.  
  32. AutoCAD also supports the Initial Graphics Exchange Standard (IGES) file
  33. format. The information comprising an AutoCAD drawing can be written out
  34. in  IGES  format, and IGES files can  be read and converted to AutoCAD's
  35. internal format.
  36.  
  37.  
  38. C.1 ASCII Drawing Interchange (DXF) Files
  39.  
  40. This  section describes AutoCAD's DXF  (drawing interchange) file format
  41. and  the commands provided to read and  write these files. DXF files are
  42. stan-  dard  ASCII  text  files. They  can  easily  be translated to the
  43. formats  of  other  CAD  systems, or  submitted  to  other  programs for
  44. specialized analysis.
  45.  
  46.  
  47. C.1.1 DXFOUT Command - Writing a DXF File
  48.  
  49. You  can generate a drawing interchange file from an existing drawing by
  50. means of the Drawing Editor's DXFOUT command. The command format is:
  51.  
  52.     Command: DXFOUT File name <default>: (name or RETURN)
  53.  
  54. The  default name for the output file is the same as that of the current
  55. drawing, but with a file type of ".dxf". If you specify an explicit file
  56. name,  do not include a file type; ".dxf" is assumed. If a file with the
  57. same  name  already  exists,  it  is  deleted.  Next,  DXFOUT  asks what
  58. precision
  59.  
  60.                                                                           1
  61.  AutoCAD Reference Manual
  62.  
  63. you  want for floating-point numbers and permits output of a partial DXF
  64. file containing only selected objects.
  65.  
  66.     Enter decimal places of accuracy (0 to 16)/Entities/Binary <6>:
  67.  
  68. The  "Binary" option is described later in this appendix. If you respond
  69. with "Entities" (or just "E"), DXFOUT will ask you to select the objects
  70. you  want  written to the DXF file.  Only the objects you select will be
  71. included   in   the  output  file   -  symbol  tables  (including  Block
  72. Definitions)  will  not  be included.  Once  you've selected the desired
  73. objects, AutoCAD will prompt again for the numeric precision:
  74.  
  75.     Enter decimal places of accuracy (0 to 16)/Binary <6>:
  76.  
  77.  
  78. C.1.2 DXFIN Command - Loading a DXF File
  79.  
  80. A  drawing interchange file can be  converted into an AutoCAD drawing by
  81. means  of  the DXFIN command. First  enter  the Drawing Editor using the
  82. "Create  new drawing" task from the Main Menu. Then issue the DXFIN com-
  83. mand.
  84.  
  85.     Command:  DXFIN   File name:  (name)
  86.  
  87. Enter the name of the drawing interchange file to be loaded.
  88.  
  89.  
  90. Full DXFIN
  91.  
  92. To  load  a complete DXF file, you  must  use DXFIN in an empty drawing,
  93. before  any  entities  have been drawn  and  before any additional Block
  94. definitions,   layers,  linetypes,  text   styles,  named  views,  named
  95. coordinate  systems, or named viewport configurations have been created.
  96. (If your prototype draw- ing contains any such items, use Main Menu Task
  97. 1's "name=" technique to create a new drawing without a prototype.)
  98.  
  99. If  any  errors  are  detected  during  the  input,  the  new drawing is
  100. discarded.  Otherwise,  an automatic "ZOOM All"  is performed to set the
  101. drawing extents.
  102.  
  103.  
  104. Partial DXFIN
  105.  
  106. If  the  current  drawing is not  empty,  DXFIN  loads only the ENTITIES
  107. section  of the DXF file, adding the entities found there to the current
  108. drawing. In this case, DXFIN displays the message:
  109.  
  110.     Not a new drawing -- only ENTITIES section will be input.
  111.  
  112. If  errors  are detected during such  partial  DXF input, the drawing is
  113. returned to the state it was in before the DXFIN command. Otherwise, the
  114. newly added entities are drawn.
  115.  
  116.  
  117.  
  118. 2
  119.                                     (C) Drawing Interchange and File Formats
  120.  
  121. C.1.3  DXF File Format
  122.  
  123. This section describes the format of a DXF file in detail. It contains a
  124. great deal of technical information that you need only if you're writing
  125. your own program to process DXF files. Otherwise, you can skip this sec-
  126. tion.
  127.  
  128. It would probably be helpful to produce a DXF file from a small drawing,
  129. print it out, and refer to it occasionally while reading the information
  130. presented below.
  131.  
  132.  
  133. C.1.3.1  General File Structure
  134.  
  135. A Drawing Interchange File is simply an ASCII text file with a file type
  136. of  ".dxf"  and specially-formatted text.  The overall organization of a
  137. DXF file is as follows:
  138.  
  139.   1. HEADER section - General information about the drawing is found in
  140.      this section of the DXF file.  Each parameter has a variable name
  141.      and an associated value.
  142.  
  143.   2. TABLES section -- This section contains definitions of named
  144.      items.
  145.  
  146.        o  Linetype (LTYPE) table
  147.        o  Layer table
  148.        o  Text style (STYLE) table
  149.        o  View table
  150.        o  User Coordinate System (UCS) table
  151.        o  Viewport configuration (VPORT) table
  152.        o  Drawing manager (DWGMGR) table (for future use)
  153.  
  154.   3. BLOCKS section - This section contains Block Definition entities
  155.      describing the entities comprising each Block in the drawing.
  156.  
  157.   4. ENTITIES section - This section contains the drawing entities,
  158.      including any Block References.
  159.  
  160.   5. END OF FILE
  161.  
  162. If  you  use  DXFOUT's "Entities" option,  the  resulting  DXF file will
  163. contain  only  the ENTITIES and END  OF  FILE sections, and the ENTITIES
  164. section will reflect only the objects you select for output.
  165.  
  166. A  DXF  file  is  composed of a  multiplicity  of  groups, each of which
  167. occupies two lines in the DXF file. The first line of a group is a group
  168. code,  which is a positive nonzero integer output in FORTRAN "I3" format
  169. (that  is, right justified and blank filled in a three character field).
  170. The  second  line  of the group is  the  group  value, in a format which
  171. depends on the type of the group as specified by the group code.
  172.  
  173.  
  174.  
  175.                                                                           3
  176.  AutoCAD Reference Manual
  177.  
  178. The  specific  assignment  of group codes  depends  upon  the item being
  179. described  in  the  file.  However, the  type  of  the  value this group
  180. supplies is derived from the group code in the following way:
  181.  
  182.                     Group code range   Following value
  183.                           0 - 9       String
  184.                          10 - 59      Floating-point
  185.                          60 - 79      Integer
  186.                         210 - 239     Floating-point
  187.                            999        Comment (string)
  188.  
  189. Thus  a program can easily read the value following a group code without
  190. knowing  the  particular use of this group  in  an item in the file. The
  191. appearance  of values in the DXF file  is not affected by the setting of
  192. the  UNITS  command: coordinates are  always  represented as decimal (or
  193. possibly  scientific  notation  if very  large)  numbers, and angles are
  194. always repre- sented in decimal degrees with zero degrees to the east of
  195. origin.
  196.  
  197. Variables,  table  entries, and entities are  described  by a group that
  198. intro- duces the item, giving its type and/or name, followed by multiple
  199. groups  that  supply the values associated  with  the item. In addition,
  200. special  groups  are  used for file  separators  such as markers for the
  201. beginning and end of sections, tables, and the file itself.
  202.  
  203. Entities,  table entries, and file separators are always introduced with
  204. a 0 group code that is followed by a name describing the item.
  205.  
  206.  
  207. C.1.3.2  Group Codes
  208.  
  209. Group  codes  are  used both to indicate  the  type  of the value of the
  210. group, as explained above, and to indicate the general use of the group.
  211. The  spe-  cific  function  of  the  group  code  depends  on the actual
  212. variable,  table item, or entity description. This section indicates the
  213. general use of groups, noting as "(fixed)" any that always have the same
  214. function.
  215.  
  216.    Group code                           Value type
  217.        0        Identifies the start of an entity, table entry, or file
  218.                 separator.  The text value that follows indicates which.
  219.        1        The primary text value for an entity.
  220.        2        A name; Attribute tag, Block name, etc.
  221.       3-4       Other textual or name values.
  222.        5        Entity handle expressed as a hexadecimal string.
  223.        6        Line type name (fixed).
  224.        7        Text style name (fixed).
  225.        8        Layer name (fixed).
  226.        9        Variable name identifier (used only in HEADER section of
  227.                 the DXF file).
  228.        10       Primary X coordinate (start point of a Line or Text
  229.                 entity, center of a Circle, etc.).
  230.      11-18      Other X coordinates.
  231.                                                              continued ...
  232.  
  233.  
  234. 4
  235.                                     (C) Drawing Interchange and File Formats
  236.  
  237.    Group code                           Value type
  238.        20       Primary Y coordinate.  2n values always correspond to 1n
  239.                 values and immediately follow them in the file.
  240.      21-28      Other Y coordinates.
  241.        30       Primary Z coordinate.  3n values always correspond to 1n
  242.                 and 2n values and immediately follow them in the file.
  243.      31-37      Other Z coordinates.
  244.        38       This entity's elevation if nonzero (fixed).  Output only
  245.                 if system variable FLATLAND is set to 1.
  246.        39       This entity's thickness if nonzero (fixed).
  247.      40-48      Floating-point values (text height, scale factors, etc.).
  248.        49       Repeated value - multiple 49 groups may appear in one
  249.                 entity for variable length tables (such as the dash
  250.                 lengths in the LTYPE table).  A 7x group always appears
  251.                 before the first 49 group to specify the table length.
  252.      50-58      Angles.
  253.        62       Color number (fixed).
  254.        66       "Entities follow" flag (fixed).
  255.      70-78      Integer values, such as repeat counts, flag bits, or
  256.                 modes.
  257.  210, 220, 230  X, Y, and Z components of extrusion direction.
  258.       999       Comments
  259.  
  260.  
  261. C.1.4  Comments
  262.  
  263. The  999  group  code  indicates that  the  following  line is a comment
  264. string.  DXFOUT  does  not currently include  such  groups in its output
  265. file,  but DXFIN honors them and ignores the comments. Thus, you can use
  266. the  999  group  to include comments in  a  DXF  file you've edited. For
  267. example:
  268.  
  269.     999
  270.     This is a comment.
  271.     999
  272.     This is another comment.
  273.  
  274.  
  275. C.1.5  File Sections
  276.  
  277. The DXF file is subdivided into four sections. File separator groups are
  278. used  to  delimit these file sections. The  following is an example of a
  279. void DXF file with only the section markers and table headers present.
  280.  
  281.       0                           (Begin HEADER section)
  282.     SECTION
  283.       2
  284.     HEADER
  285.         <<<<Header variable items go here>>>>
  286.       0
  287.     ENDSEC                        (End HEADER section)
  288.       0                           (Begin TABLES section)
  289.     SECTION
  290.       2
  291.  
  292.                                                                           5
  293.  AutoCAD Reference Manual
  294.  
  295.     TABLES
  296.       0
  297.     TABLE
  298.       2
  299.     VPORT
  300.      70
  301.     (viewport table maximum item count)
  302.         <<<<viewport table items go here>>>>
  303.       0
  304.     ENDTAB
  305.       0
  306.     TABLE
  307.       2
  308.     LTYPE, LAYER, STYLE, VIEW, UCS, or DWGMGR
  309.      70
  310.     (Table maximum item count)
  311.         <<<<Table items go here>>>>
  312.       0
  313.     ENDTAB
  314.       0
  315.     ENDSEC                        (End TABLES section)
  316.       0                           (Begin BLOCKS section)
  317.     SECTION
  318.       2
  319.     BLOCKS
  320.         <<<<Block definition entities go here>>>>
  321.       0
  322.     ENDSEC                        (End BLOCKS section)
  323.       0                           (Begin ENTITIES section)
  324.     SECTION
  325.       2
  326.     ENTITIES
  327.         <<<<Drawing entities go here>>>>
  328.       0
  329.     ENDSEC                        (End ENTITIES section)
  330.       0
  331.     EOF                           (End of file)
  332.  
  333.  
  334. C.1.5.1  HEADER Section
  335.  
  336. The  HEADER  section  of  the DXF  file  contains  settings of variables
  337. associated  with  the  drawing.  These  variables  are  set with various
  338. commands  and  are  the  type of  information  displayed  by  the STATUS
  339. command.  Each variable is specified in the  header section by a 9 group
  340. giving  its  name, followed by groups  that supply its value. The header
  341. variables, the groups that follow, and their meanings are listed below.
  342.  
  343. Although  this  list is very similar to  the list of system variables in
  344. Appendix A, the two lists are not identical. Be sure you're referring to
  345. the proper list.
  346.  
  347.  
  348.  
  349. 6
  350.                                     (C) Drawing Interchange and File Formats
  351.  
  352.   $ACADVER       1     the AutoCAD drawing database version number.
  353.   $ANGBASE      50     Angle 0 direction.
  354.   $ANGDIR       70     1=clockwise angles, 0=counterclockwise.
  355.   $ATTDIA       70     Attribute entry dialogues, 1 = on, 0 = off
  356.   $ATTMODE      70     Attribute visibility: 0=none, 1=normal, 2=all.
  357.   $ATTREQ       70     Attribute prompting during INSERT, 1 = on, 0 = off
  358.   $AUNITS       70     UNITS format for angles.
  359.   $AUPREC       70     UNITS precision for angles.
  360.   $AXISMODE     70     axis on if nonzero.
  361.   $AXISUNIT   10,20    axis X and Y tick spacing.
  362.   $BLIPMODE     70     blip mode on if nonzero.
  363.   $CECOLOR      62     entity color number; 0 = BYBLOCK, 256 = BYLAYER.
  364.   $CELTYPE       6     entity linetype name, or BYBLOCK or BYLAYER.
  365.   $CHAMFERA     40     first chamfer distance.
  366.   $CHAMFERB     40     second chamfer distance.
  367.   $CLAYER        8     current layer name.
  368.   $COORDS       70     0=static coordinate display, 1=continuous update,
  369.                        2="d<a" format.
  370.   $DIMALT       70     alternate unit dimensioning performed if nonzero.
  371.   $DIMALTD      70     alternate unit decimal places.
  372.   $DIMALTF      40     alternate unit scale factor.
  373.   $DIMAPOST      1     alternate dimensioning suffix
  374.   $DIMASO       70     1=create associative dimensioning, 0=draw
  375.                        individual entities.
  376.   $DIMASZ       40     dimensioning arrow size.
  377.   $DIMBLK        2     arrow block name.
  378.   $DIMBLK1       1     first arrow block name.
  379.   $DIMBLK2       1     second arrow block name.
  380.   $DIMCEN       40     size of center mark/lines.
  381.   $DIMDLE       40     dimension line extension.
  382.   $DIMDLI       40     dimension line increment.
  383.   $DIMEXE       40     extension line extension.
  384.   $DIMEXO       40     extension line offset.
  385.   $DIMLFAC      40     linear measurements scale factor.
  386.   $DIMLIM       70     dimension limits generated if nonzero.
  387.   $DIMPOST       1     general dimensioning suffix
  388.   $DIMRND       40     rounding value for dimension distances.
  389.   $DIMSAH       70     use separate arrow blocks if nonzero.
  390.   $DIMSCALE     40     overall dimensioning scale factor.
  391.   $DIMSE1       70     first extension line suppressed if nonzero.
  392.   $DIMSE2       70     second extension line suppressed if nonzero.
  393.   $DIMSHO       70     1=Recompute dimensions while dragging,
  394.                        0=drag original image.
  395.   $DIMSOXD      70     suppress outside-extensions dimension lines
  396.                        if nonzero.
  397.   $DIMTAD       70     text above dimension line if nonzero.
  398.   $DIMTIH       70     text inside horizontal if nonzero.
  399.   $DIMTIX       70     force text inside extensions if nonzero.
  400.   $DIMTM        40     minus tolerance.
  401.   $DIMTOFL      70     if text outside extensions, force line between
  402.                        extensions if nonzero.
  403.   $DIMTOH       70     text outside horizontal if nonzero.
  404.  
  405.  
  406.                                                                           7
  407.  AutoCAD Reference Manual
  408.  
  409.   $DIMTOL       70     dimension tolerances generated if nonzero.
  410.   $DIMTP        40     plus tolerance.
  411.   $DIMTSZ       40     dimensioning tick size: 0=no ticks.
  412.   $DIMTVP       40     text vertical position.
  413.   $DIMTXT       40     dimensioning text height.
  414.   $DIMZIN       70     zero suppression for "feet & inch" dimensions.
  415.   $DRAGMODE     70     0=off, 1=on, 2=auto.
  416.   $ELEVATION    40     current elevation set by ELEV command.
  417.   $EXTMAX    10,20,30  XY drawing extents upper right corner (in WCS).
  418.   $EXTMIN    10,20,30  XY drawing extents lower left corner (in WCS).
  419.   $FILLETRAD    40     fillet radius.
  420.   $FILLMODE     70     FILL mode on if nonzero.
  421.   $FLATLAND     70     force compatibility with older versions if nonzero.
  422.   $HANDLING     70     handles enabled if nonzero.
  423.   $HANDSEED      5     next available handle.
  424.   $INSBASE   10,20,30  insertion base set by BASE command (in WCS).
  425.   $LIMCHECK     70     nonzero if limits checking is on.
  426.   $LIMMAX     10,20    XY drawing limits upper right corner (in WCS).
  427.   $LIMMIN     10,20    XY drawing limits lower left corner (in WCS).
  428.   $LTSCALE      40     global linetype scale.
  429.   $LUNITS       70     UNITS format for coordinates and distances.
  430.   $LUPREC       70     UNITS precision for coordinates and distances.
  431.   $MENU          1     name of menu file.
  432.   $MIRRTEXT     70     MIRROR text if nonzero.
  433.   $ORTHOMODE    70     ORTHO mode on if nonzero.
  434.   $OSMODE       70     running object snap modes.
  435.   $PDMODE       70     point display mode.
  436.   $PDSIZE       40     point display size.
  437.   $PLINEWID     40     default Polyline width.
  438.   $QTEXTMODE    70     quick text mode on if nonzero.
  439.   $REGENMODE    70     REGENAUTO mode on if nonzero.
  440.   $SKETCHINC    40     sketch record increment.
  441.   $SKPOLY       70     0=sketch lines, 1=sketch polylines.
  442.   $SPLFRAME     70     spline control polygon display, 1 = on, 0 = off.
  443.   $SPLINESEGS   70     number of line segments per spline patch.
  444.   $SPLINETYPE   70     spline curve type for "PEDIT Spline"
  445.                        (see Appendix A).
  446.   $SURFTAB1     70     number of mesh tabulations in first direction.
  447.   $SURFTAB2     70     number of mesh tabulations in second direction.
  448.   $SURFTYPE     70     surface type for "PEDIT Smooth" (see Appendix A).
  449.   $SURFU        70     surface density (for "PEDIT Smooth") in M direction.
  450.   $SURFV        70     surface density (for "PEDIT Smooth") in N direction.
  451.   $TDCREATE     40     date/time of drawing creation.
  452.   $TDINDWG      40     cumulative editing time for this drawing.
  453.   $TDUPDATE     40     date/time of last drawing update.
  454.   $TDUSRTIMER   40     user elapsed timer.
  455.   $TEXTSIZE     40     default text height.
  456.   $TEXTSTYLE     7     current text style name.
  457.   $THICKNESS    40     current thickness set by ELEV command.
  458.   $TRACEWID     40     default Trace width.
  459.   $UCSNAME       1     Name of current UCS.
  460.   $UCSORG    10,20,30  origin of current UCS (in WCS).
  461.  
  462.  
  463. 8
  464.                                     (C) Drawing Interchange and File Formats
  465.  
  466.   $UCSXDIR   10,20,30  direction of current UCS's X axis
  467.                        (in World coordinates).
  468.   $UCSYDIR   10,20,30  direction of current UCS's Y axis
  469.                        (in World coordinates).
  470.   $USERI1 - 5   70     Five integer variables intended for use by
  471.                        third-party developers.
  472.   $USERR1 - 5   40     Five real variables intended for use by
  473.                        third-party developers.
  474.   $USRTIMER     70     0=timer off, 1=timer on.
  475.   $WORLDVIEW    70     1=set UCS to WCS during DVIEW/VPOINT,
  476.                        0=don't change UCS
  477.  
  478. The  header  variables listed below existed  prior to AutoCAD Release 10
  479. but now have independent settings for each active viewport. They are not
  480. output  by  DXFOUT  unless system variable  FLATLAND  is set to 1. DXFIN
  481. honors  these variables when read from DXF  files, but if a VPORT symbol
  482. table  with  "*ACTIVE" entries is present (as  is  true for any DXF file
  483. produced by Release 10 or higher), the values in the VPORT table entries
  484. will override the values of these header variables.
  485.  
  486.   $FASTZOOM     70     fast zoom enabled if nonzero.
  487.   $GRIDMODE     70     grid mode on if nonzero.
  488.   $GRIDUNIT   10,20    grid X and Y spacing.
  489.   $SNAPANG      50     snap grid rotation angle.
  490.   $SNAPBASE   10,20    snap/grid base point (in UCS).
  491.   $SNAPISOPAIR  70     isometric plane: 0=left, 1=top, 2=right.
  492.   $SNAPMODE     70     snap mode on if nonzero.
  493.   $SNAPSTYLE    70     snap style: 0=standard, 1=isometric.
  494.   $SNAPUNIT   10,20    snap grid X and Y spacing.
  495.   $VIEWCTR    10,20    XY center of current view on screen.
  496.   $VIEWDIR   10,20,30  viewing direction (direction from target, in WCS).
  497.   $VIEWSIZE     40     height of view.
  498.  
  499. The date/time variables ($TDCREATE and $TDUPDATE) are output as real num-
  500. bers in the format:
  501.  
  502.     <Julian date>.<Fraction>
  503.  
  504. The elapsed time variables ($TDINDWG and $TDUSRTIMER) have a similar
  505. format:
  506.  
  507.     <Number of days>.<Fraction>
  508.  
  509.  
  510. C.1.5.2  TABLES Section
  511.  
  512. The  TABLES  section  contains  several tables,  each  of  which in turn
  513. contains a variable number of table entries. The order of the tables may
  514. change,  but  the LTYPE table will  always precede the LAYER table. Each
  515. table  is  intro- duced with a 0  group  with the label "TABLE". This is
  516. followed  by  a 2 group identifying  the particular table (VPORT, LTYPE,
  517. LAYER,  STYLE,  VIEW, UCS, or DWGMGR) and  a 70 group that specifies the
  518. maximum number of table entries
  519.  
  520.                                                                           9
  521.  AutoCAD Reference Manual
  522.  
  523. that  may follow. The tables in a drawing may contain deleted items, but
  524. these  are  not written to the DXF  file.  Thus, fewer table entries may
  525. follow the table header than are indicated by the 70 group, so don't use
  526. the  count  in  the  70 group as an  index  to  read in the table. It is
  527. provided so that your program to read DXF files can allocate an array in
  528. advance large enough to hold all the table entries that follow.
  529.  
  530. Following  this header for each table  are the table entries. Each table
  531. item  consists  of  a 0 group identifying  the  item type (same as table
  532. name,  e.g., "LTYPE" or "LAYER"), a 2 group giving the name of the table
  533. entry,  a 70 group specifying flags relevant to the table entry (defined
  534. for  each table below), and additional groups that give the value of the
  535. table  entry.  The end of each table is  indicated by a 0 group with the
  536. value "ENDTAB".
  537.  
  538. If any table entry has bit value 64 set in its group 70 flags, the table
  539. entry was referenced by at least one entity in the drawing the last time
  540. the  drawing editor was entered to  edit this drawing. This "referenced"
  541. flag  is for the benefit of the PURGE command; it can be ignored by most
  542. programs that read DXF files, and need not be set by programs that write
  543. DXF files.
  544.  
  545. The  following  are  the groups used for  each  type  of table item. All
  546. groups are present for each table item.
  547.  
  548.   LTYPE    3 (descriptive text for linetype), 72 (alignment code), 73
  549.            (number of dash length items), 40 (total pattern length), 49
  550.            (dash length 1), 49 (dash length 2), . . .
  551.  
  552.   LAYER    62 (color number, negative if layer is off), 6 (linetype
  553.            name).  The 1 bit is set in the 70 group flags if the layer is
  554.            frozen.
  555.  
  556.   STYLE    40 (fixed text height; 0 if not fixed), 41 (width factor), 50
  557.            (obliquing angle), 71 (text generation flags), 42 (last height
  558.            used), 3 (primary font file name), 4 ("bigfont" file name;
  559.            blank if none).  If the third bit (4) is set in the 70 group
  560.            flags, this is a vertically-oriented text style.
  561.  
  562.            A STYLE table item is used to record shape file LOAD requests
  563.            also.  In this case the first bit (1) is set in the 70 group
  564.            flags and only the 3 group (shape file name) is meaningful
  565.            (all the other groups are output, however).
  566.  
  567.            The "text generation flags" are a bit-coded field with the
  568.            following bit meanings:
  569.  
  570.                 Flag bit value                Meaning
  571.                        2        Text is backwards (mirrored in X)
  572.                        4        Text is upside down (mirrored in Y)
  573.  
  574.  
  575.  
  576.  
  577.  
  578. 10
  579.                                     (C) Drawing Interchange and File Formats
  580.  
  581.   VIEW     40 and 41 (view height and width), 10 and 20 (view center
  582.            point), 11, 21, 31 (view direction from target, in WCS), 12,
  583.            22, 32 (target point, in WCS), 42 (lens length), 43 and 44
  584.            (front and back clipping planes-offsets from target point), 50
  585.            (twist angle), 71 view mode (see VIEWMODE system variable
  586.            Appendix A).
  587.  
  588.   UCS      10, 20, 30 (origin), 11, 21, 31 (X axis direction), 12, 22, 32
  589.            (Y axis direction).  All in World coordinates.
  590.  
  591.   VPORT    10 and 20 (lower left corner of viewport; 0.0 to 1.0), 11 and
  592.            21 (upper right corner), 12 and 22 (view center point), 13 and
  593.            23 (snap base point), 14 and 24 (snap spacing, X and Y), 15
  594.            and 25 (grid spacing, X and Y), 16, 26, 36 (view direction
  595.            from target point), 17, 27, 37 (view target point), 40 (view
  596.            height), 41 (viewport aspect ratio), 42 (lens length), 43 and
  597.            44 (front and back clipping planes; offsets from target
  598.            point), 50 (snap rotation angle), 51 (view twist angle), 71
  599.            (view mode; see VIEWMODE system variable in Appendix A), 72
  600.            (circle zoom percent), 73 (fast zoom setting), 74 (UCSICON
  601.            setting), 75 (snap on/off), 76 (grid on/off), 77 (snap style),
  602.            78 (snap isopair).
  603.  
  604.            The VPORT table is unique in that it may contain several
  605.            entries with the same name (indicating a multiple-viewport
  606.            configuration).  The entries corresponding to the active view-
  607.            port configuration all have the name "*ACTIVE".  The first
  608.            such entry describes the current viewport.
  609.  
  610.   DWGMGR   For future use.  Fields not yet defined.
  611.  
  612.  
  613. C.1.5.3  BLOCKS Section
  614.  
  615. The  BLOCKS section of the DXF  file contains all the Block Definitions.
  616. This  section contains the entities that make  up the Blocks used in the
  617. drawing, including "anonymous" Blocks generated by the HATCH command and
  618. by  associative dimensioning. The format of the entities in this section
  619. is  identical to those in the ENTITIES section described below, so refer
  620. to  that section for details. All  entities in the BLOCKS section appear
  621. between BLOCK and ENDBLK entities. BLOCK and ENDBLK entities appear only
  622. in  the BLOCKS section. Block definitions  are never nested (that is, no
  623. BLOCK or ENDBLK entity ever appears within another BLOCK-ENDBLK pair).
  624.  
  625.  
  626. C.1.5.4  ENTITIES Section
  627.  
  628. Entity  items appear in both the BLOCK  and ENTITIES sections of the DXF
  629. file.  The appearance of entities in the two sections is identical, with
  630. the exception that entities in the BLOCK section never have handles. The
  631. following  gives  the format of each entity  as  it appears in the file.
  632. Some  groups that define an entity  always appear, and some are optional
  633. and  appear  only  if  they differ  from  their  default  values. In the
  634. following
  635.  
  636.                                                                          11
  637.  AutoCAD Reference Manual
  638.  
  639. discussion, groups that always occur are given by their group number and
  640. function, while optional groups are indicated by "-optional N" following
  641. the group description. "N" is the default value if the group is omitted.
  642.  
  643. Programs  that  read  DXF  files  should  not  assume  that  the  groups
  644. describing  an  entity  occur in the order  given  here.  The end of the
  645. groups  that  make  up  an  entity is  indicated  by  the  next 0 group,
  646. beginning the next entity or indicating the end of the section.
  647.  
  648. Remember  that  a DXF file is  a  complete representation of the drawing
  649. data-  base, and that as AutoCAD is further enhanced, new groups will be
  650. added  to entities to accommodate  additional features. Writing your DXF
  651. processing  program  in a table-driven  way, making no assumptions about
  652. the  order of groups in an entity, and ignoring any groups not presently
  653. defined,  will make it much easier  to accommodate DXF files from future
  654. releases of AutoCAD.
  655.  
  656. Each entity begins with a 0 group identifying the entity type. The names
  657. used  for the entities are given in the table that follows. Every entity
  658. contains an 8 group that gives the name of the layer on which the entity
  659. resides.  Each entity may have  elevation, thickness, linetype, or color
  660. information associated with it. If handles are enabled, every entity has
  661. a  5 group containing its handle (as a string representing a hexadecimal
  662. number). The following groups are included only if the entity has nonde-
  663. fault values for these properties.
  664.  
  665.   Group code                         Meaning
  666.        6      Linetype name (if not "BYLAYER").  The special name "BYBLOCK"
  667.               indicates a floating linetype.
  668.  
  669.       38      Elevation (if nonzero).  Output only if system variable
  670.               FLATLAND is 1.  Otherwise, Z coordinates are supplied as
  671.               3x-groups as part of each of the entity's defining points.
  672.  
  673.       39      Thickness (if nonzero).
  674.  
  675.       62      Color number (if not "BYLAYER").  Zero indicates the
  676.               "BYBLOCK" (floating) color.
  677.  
  678.      210,     These groups are included for each Line, Point, Circle, Shape,
  679.      220,     Text, Arc, Trace, Solid, Block Reference, Polyline, Dimension,
  680.      230      Attribute, and Attribute Definition entity if its extrusion
  681.               direction is not parallel to the World Z axis.  The indicate
  682.               the X, Y, and Z components of the entity's extrusion direction.
  683.  
  684. The  rest of the groups that make up an entity item are described below.
  685. Many  of the entities include "flag" groups. These are integer codes (6x
  686. or  7x  groups) that encode various  pieces of information regarding the
  687. entity, and are specific to the particular entity type. In the following
  688. descrip-  tions,  the  term  "bit-coded"  means  that  the flag contains
  689. various  true/false values coded as the sum of the bit values given. Any
  690. bits  not  defined in the following  section  should be ignored in these
  691. fields and set to zero when constructing a DXF file.
  692.  
  693. 12
  694.                                     (C) Drawing Interchange and File Formats
  695.  
  696.   LINE      10, 20, 30 (start point), 11, 21, 31 (end point).
  697.  
  698.   POINT     10, 20, 30 (point), 50 (angle of X axis for the UCS in effect
  699.             when the Point was drawn -optional 0, for use when PDMODE is
  700.             nonzero).
  701.  
  702.   CIRCLE    10, 20, 30 (center), 40 (radius).
  703.  
  704.   ARC       10, 20, 30 (center), 40 (radius), 50 (start angle), 51 (end
  705.             angle).
  706.  
  707.   TRACE     Four points defining the corners of the trace: (10, 20, 30),
  708.             (11, 21, 31), (12, 22, 32), and (13, 23, 33).
  709.  
  710.   SOLID     Four points defining the corners of the solid: (10, 20, 30),
  711.             (11, 21, 31), (12, 22, 32), and (13, 23, 33).  If only three
  712.             points were entered (forming a triangular solid), the third
  713.             and fourth points will be the same.
  714.  
  715.   TEXT      10, 20, 30 (insertion point), 40 (height), 1 (text value), 50
  716.             (rotation angle -optional 0), 41 (relative X scale factor
  717.             -optional 1), 51 (obliquing angle -optional 0), 7 (text style
  718.             name -optional "STANDARD"), 71 (text generation flags
  719.             -optional 0), 72 (justification type -optional 0), 11, 21, 31
  720.             (alignment point -optional, appears only if 72 group is
  721.             present and nonzero).
  722.  
  723.             The "text generation flags" are a bit-coded field with mean-
  724.             ings as follows:
  725.  
  726.                  Flag bit value                Meaning
  727.                        2         Text is backwards (mirrored in X)
  728.                        4         Text is upside down (mirrored in Y)
  729.  
  730.             The "justification type" value (not bit-coded) indicates the
  731.             text justification style used on this entity, as shown in the
  732.             following table.
  733.  
  734.               Value                       Meaning
  735.                 0    Text is left justified
  736.                 1    Text is centered along its baseline
  737.                 2    Text is right justified
  738.                 3    Text is aligned between two points (height varies)
  739.                 4    Text is "middle" (fully) centered
  740.                 5    Text is fit between two points (width varies)
  741.  
  742.             If the justification is anything other than 0 (left justi-
  743.             fied), 11, 21, and 31 groups will also appear in the entity
  744.             to specify the alignment point of the text (center, right-
  745.             most, or second alignment point).
  746.  
  747.             DXFOUT handles ASCII control characters in text strings by
  748.             expanding the character into a "^" (caret) followed by the
  749.  
  750.                                                                          13
  751.  AutoCAD Reference Manual
  752.  
  753.             appropriate letter.  For example, an ASCII Control-G (BEL,
  754.             decimal code 7) is output as "^G".  If the text itself con-
  755.             tains a caret character, it is expanded to "^ " (caret,
  756.             space).  DXFIN performs the complementary conversion.
  757.  
  758.   SHAPE     10, 20, 30 (insertion point), 40 (size), 2 (shape name), 50
  759.             (rotation angle -optional 0), 41 (relative X scale factor
  760.             -optional 1), 51 (obliquing angle -optional 0).
  761.  
  762.   BLOCK     2 (Block name), 70 (Block type flags), 10, 20, 30 (Block base
  763.             point).  Appears only in BLOCKS section.  The "Block type
  764.             flags" are bit-coded, with the following bit meanings:
  765.  
  766.               Flag bit value                   Meaning
  767.                     1         This is an "anonymous" Block generated by
  768.                               hatching, associative dimensioning, or
  769.                               other internal operations.
  770.                     2         This Block has Attributes.
  771.  
  772.   ENDBLK    No groups.  Appears only in BLOCKS section.
  773.  
  774.   INSERT    66 ("Attributes follow" flag -optional 0), 2 (Block name),
  775.             10, 20, 30 (insertion point), 41 (X scale factor -optional
  776.             1), 42 (Y scale factor -optional 1), 43 (Z scale factor
  777.             -optional 1), 50 (rotation angle -optional 0), 70 and 71
  778.             (column and row counts -optional 1), 44 and 45 (column and
  779.             row spacing -optional 0).
  780.  
  781.             If the value of the "Attributes follow" flag is 1, a series
  782.             of Attribute (ATTRIB) entities is expected to follow the
  783.             INSERT, terminated by a sequence end (SEQEND) entity.
  784.  
  785.   ATTDEF    10, 20, 30 (text start), 40 (text height), 1 (default value,
  786.             see TEXT above for handling of ASCII control characters), 3
  787.             (prompt string), 2 (tag string), 70 (Attribute flags), 73
  788.             (field length -optional 0), 50 (text rotation -optional 0),
  789.             41 (relative X scale factor -optional 1), 51 (obliquing angle
  790.             -optional 0), 7 (text style name -optional "STANDARD"), 71
  791.             (text generation flags -optional 0, see TEXT above), 72 (text
  792.             justification type -optional 0, see TEXT above)), 11, 21, 31
  793.             (alignment point -optional, appears only if 72 group is
  794.             present and nonzero).
  795.  
  796.             The "Attribute flags" are a bit-coded field in which the bits
  797.             have the following meanings:
  798.  
  799.               Flag bit value                   Meaning
  800.                     1         Attribute is invisible (does not display)
  801.                     2         This is a constant Attribute
  802.                     4         Verification is required on input of this
  803.                               Attribute.
  804.                     8         Attribute is preset (no prompt during
  805.                               insertion)
  806.  
  807. 14
  808.                                     (C) Drawing Interchange and File Formats
  809.  
  810.   ATTRIB    10, 20, 30 (text start), 40 (text height), 1 (value, see TEXT
  811.             above for handling of ASCII control characters), 2 (Attribute
  812.             tag), 70 (Attribute flags; see ATTDEF above), 73 (field
  813.             length -optional 0), 50 (text rotation -optional 0), 41 (rel-
  814.             ative X scale factor -optional 1), 51 (obliquing angle
  815.             -optional 0), 7 (text style name -optional "STANDARD"), 71
  816.             (text generation flags -optional 0, see TEXT above), 72 (text
  817.             justification type -optional 0, see TEXT above), 11, 21, 31
  818.             (alignment point -optional, appears only if 72 group is
  819.             present and nonzero).
  820.  
  821.   POLYLINE  66 ("vertices follow flag"), 70 (Polyline flags), 40 (default
  822.             starting width), 41 (default ending width), 71 and 72 (poly-
  823.             gon mesh M and N vertex counts -optional 0), 73 and 74
  824.             (smooth surface M and N densities -optional 0), 75 (smooth
  825.             surface type -optional 0).  The default widths apply to any
  826.             vertex that doesn't supply widths (see below).
  827.  
  828.             The "vertices follow" flag is always 1, indicating that a
  829.             series of VERTEX entities is expected to follow the POLYLINE,
  830.             terminated by a sequence end (SEQEND) entity.  The "polyline
  831.             flags" group is a bit-coded field with bits defined as fol-
  832.             lows:
  833.  
  834.              Flag bit value                    Meaning
  835.                     1        This is a closed Polyline (or a polygon
  836.                              mesh closed in the M direction)
  837.                     2        Curve-fit vertices have been added
  838.                     4        Spline-fit vertices have been added
  839.                     8        This is a 3D Polyline
  840.                    16        This is a 3D polygon mesh.  Group 75 indi-
  841.                              cates the smooth surface type, as follows:
  842.  
  843.                                0 = no smooth surface fitted
  844.                                5 = quadratic B-spline surface
  845.                                6 = cubic B-spline surface
  846.                                8 = Bezier surface
  847.  
  848.                    32        The polygon mesh is closed in the N direc-
  849.                              tion
  850.  
  851.   VERTEX    10, 20, 30 (location), 40 (starting width -optional, see
  852.             above), 41 (ending width -optional, see above), 42 (bulge),
  853.             70 (vertex flags), 50 (curve fit tangent direction
  854.             -optional).  The bulge is the tangent of 1/4 the included
  855.             angle for an arc segment, made negative if the arc goes
  856.             clockwise from the start point to the end point; a bulge of 0
  857.             indicates a straight segment, and a bulge of 1 is a semicir-
  858.             cle.  The meanings of the bit-coded "vertex flags" are shown
  859.             in the following table.
  860.  
  861.  
  862.  
  863.  
  864.                                                                          15
  865.  AutoCAD Reference Manual
  866.  
  867.              Flag bit value                    Meaning
  868.                    1         Extra vertex created by curve fitting
  869.                    2         Curve fit tangent defined for this vertex.
  870.                              A curve fit tangent direction of 0 may be
  871.                              omitted from the DXF output, but is signif-
  872.                              icant if this bit is set.
  873.                    4         Unused (never set in DXF files)
  874.                    8         Spline vertex created by spline fitting
  875.                    16        Spline frame control point
  876.                    32        3D Polyline vertex
  877.                    64        3D polygon mesh vertex
  878.  
  879.   SEQEND    No fields.  This entity marks the end of vertices (VERTEX
  880.             type name) for a Polyline, or the end of Attribute entities
  881.             (ATTRIB type name) for an INSERT entity that has Attributes
  882.             (indicated by 66 group present and nonzero in INSERT entity).
  883.  
  884.   3DLINE    10, 20, 30 (start point), 11, 21, 31 (end point).
  885.  
  886.   3DFACE    Four points defining the corners of the face: (10, 20, 30),
  887.             (11, 21, 31), (12, 22, 32), and (13, 23, 33).  70 (invisible
  888.             edge flags -optional 0).  If only three points were entered
  889.             (forming a triangular face), the third and fourth points will
  890.             be the same.  The meanings of the bit-coded "invisible edge
  891.             flags" are shown in the following table.
  892.  
  893.                       Flag bit value           Meaning
  894.                              1        First edge is invisible
  895.                              2        Second edge is invisible
  896.                              4        Third edge is invisible
  897.                              8        Fourth edge is invisible
  898.  
  899.   DIMENSION 2 (name of pseudo-Block containing the current dimension pic-
  900.             ture), 10, 20, 30 (definition point for all dimension types),
  901.             11, 21, 31 (middle point of dimension text), 12, 22, 32
  902.             (insertion point for clones of a dimension (for BASELINE and
  903.             CONTINUE), 70 (Dimension type; 0=rotated, horizontal, or ver-
  904.             tical; 1=aligned; 2=angular; 3=diameter; 4=radius - the value
  905.             128 is added to this field if the dimension text has been
  906.             positioned at a user-defined location rather than at the
  907.             default location), 1 (dimension text explicitly entered by
  908.             the user.  If null, the dimension measurement is drawn as the
  909.             text.  Otherwise, this text is drawn (but if it includes the
  910.             sequence "<>", the dimension measurement is drawn in place of
  911.             the "<>")), 13, 23, 33 (definition point for linear and angu-
  912.             lar dimensions), 14, 24, 34 (definition point for linear and
  913.             angular dimensions), 15, 25, 35 (definition point for diame-
  914.             ter, radius, and angular dimensions), 16, 26, 36 (point
  915.             defining dimension arc for angular dimensions), 40 (leader
  916.             length for radius and diameter dimensions), 50 (angle of
  917.             rotated, horizontal, or vertical linear dimensions).
  918.  
  919.  
  920.  
  921. 16
  922.                                     (C) Drawing Interchange and File Formats
  923.  
  924.             In addition, all dimension types have an optional group (code
  925.             51) that indicates the "horizontal" direction for the Dimen-
  926.             sion entity.  This determines the orientation of dimension
  927.             text and dimension lines for horizontal, vertical and rotated
  928.             linear dimensions.  The group value is the negative of the
  929.             ECS angle of the UCS X axis in effect when the Dimension was
  930.             drawn.  In other words, the X axis of the UCS in effect when
  931.             the Dimension was drawn is always parallel to the XY plane
  932.             for the Dimension's ECS, and the angle between the UCS X axis
  933.             and the ECS X axis is a single 2D angle.  The value in group
  934.             51 is the angle from "horizontal" (the effective X axis) to
  935.             the ECS X axis.  Entity Coordinate Systems (ECS) are
  936.             described later in this section.
  937.  
  938.             For all dimension types, the following groups represent 3D
  939.             WCS points, regardless of the FLATLAND setting.
  940.  
  941.                 10, 20, 30
  942.                 13, 23, 33
  943.                 14, 24, 34
  944.                 15, 25, 35
  945.  
  946.             For all dimension types, the following groups represent ECS
  947.             points, and are 2D or 3D depending on the FLATLAND setting.
  948.  
  949.                 11, 21(, 31)
  950.                 12, 22(, 32)
  951.                 16, 26(, 36)
  952.  
  953.   Linear    (13,23,33)   The point used to specify the first extension line.
  954.             (14,24,34)   The point used to specify the second extension line.
  955.             (10,20,30)   The point used to specify the dimension line.
  956.  
  957.   Angular   (13,23,33) and (14,24,34)  The endpoints of the first line
  958.             (10,20,30) and (15,25,35)  The endpoints of the second line
  959.             (16,26,36)                 The point used to specify the dimen-
  960.                                        sion line arc
  961.  
  962.   Diameter  (15,25,35)   The point used to pick the circle/arc to dimension
  963.             (10,20,30)   The point on that circle directly across from the
  964.                          pick point.
  965.  
  966.   Radius    (15,25,35)   The point used to pick the circle/arc to dimension
  967.             (10,20,30)   The center of that circle.
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.                                                                          17
  979.  AutoCAD Reference Manual
  980.  
  981. Entity Coordinate Systems (ECS)
  982.  
  983. To  save space in the drawing database (and in the DXF file), the points
  984. associated  with  each entity are expressed  in  terms of its own Entity
  985. Coor-  dinate System (ECS). The  Entity Coordinate System allows AutoCAD
  986. to  use  a much more compact  means of representation for entities. With
  987. ECS,  the only additional information needed to describe its position in
  988. 3D  space  is  the 3D vector describing the  Z  axis of the ECS, and the
  989. elevation value.
  990.  
  991. For a given Z axis (or extrusion) direction, there is an infinite number
  992. of coordinate systems, defined by translating the origin in 3D space and
  993. by  rotating the X and Y axes around the Z axis. However, for the same Z
  994. axis  direction, there is only one  Entity Coordinate System. It has the
  995. follow- ing properties:
  996.  
  997.   o  Its origin coincides with the WCS origin.
  998.   o  The orientation of the X and Y axes within the XY plane are calcu-
  999.      lated in an arbitrary, but consistent manner.  AutoCAD performs
  1000.      this calculation using the "arbitrary axis" algorithm described
  1001.      below.
  1002.  
  1003. For some entities, the ECS is equivalent to the World Coordinate System and
  1004. all points (DXF groups 10-37) are expressed in World coordinates.  See the
  1005. following table.
  1006.  
  1007.                   Entities                        Notes
  1008.         LINE, POINT, 3DFACE, 3D       These entities do not lie in
  1009.         Polyline, 3D Vertex, 3D       a particular plane.  All
  1010.         Mesh, 3D Mesh vertex          points are expressed in
  1011.                                       World coordinates.  Of these
  1012.                                       entities, only Lines and
  1013.                                       Points can be extruded;
  1014.                                       their extrusion direction can
  1015.                                       differ from the World Z axis.
  1016.  
  1017.         CIRCLE, ARC, SOLID, TRACE,    These entities are planar in
  1018.         TEXT, ATTRIB, ATTDEF, SHAPE,  nature.  All points are
  1019.         INSERT, 2D Polyline, 2D       expressed in Entity coordi-
  1020.         Vertex                        nates.  All these entities
  1021.                                       can be extruded; their
  1022.                                       extrusion direction can
  1023.                                       differ from the World Z axis.
  1024.  
  1025.         DIMENSION                     Some of a Dimension's points are
  1026.                                       expressed in WCS, and some in ECS.
  1027.  
  1028.         Others                        The remaining entities have
  1029.                                       no point data and their
  1030.                                       coordinate systems are
  1031.                                       therefore irrelevant.
  1032.  
  1033. Once AutoCAD has established the ECS for a given entity, here's how it
  1034. works:
  1035.  
  1036. 18
  1037.                                     (C) Drawing Interchange and File Formats
  1038.  
  1039.   o  The elevation value stored with an entity indicates how far along
  1040.      the Z axis to shift the XY plane from the WCS origin to make it
  1041.      coincide with the plane that the entity is in.  How much of this
  1042.      is the user-defined elevation is unimportant.
  1043.   o  Any 2D points describing the entity that were entered through the
  1044.      UCS are transformed into the corresponding 2D points in the ECS,
  1045.      which (more often than not) is shifted and rotated with respect to
  1046.      the UCS.
  1047.  
  1048. A few ramifications of this process are:
  1049.  
  1050.   o  You can not reliably find out what UCS was in effect when an
  1051.      entity was acquired.  You can only find out where the entity is in
  1052.      the current UCS if the current UCS has the same Z axis direction
  1053.      as the original UCS (i.e., they both reduce to the same ECS).
  1054.   o  When you enter the XY coordinates of an entity in a given UCS and
  1055.      then do a DXFOUT, you probably won't recognize those XY coordi-
  1056.      nates in the DXF file.  You'll have to know the method by which
  1057.      AutoCAD calculates the X and Y axes in order to work with these
  1058.      values.
  1059.   o  The elevation value stored with an entity and output in DXF files
  1060.      will be a sum of the Z coordinate difference between the UCS XY
  1061.      plane and the ECS XY plane, and the elevation value that the user
  1062.      specified at the time the entity was drawn.
  1063.  
  1064.  
  1065. Arbitrary Axis Algorithm
  1066.  
  1067. The  arbitrary axis algorithm is used by AutoCAD internally to implement
  1068. the  "arbitrary but consistent" generation  of Entity Coordinate Systems
  1069. for all entities except Lines, Points, 3D Faces, and 3D Polylines, which
  1070. contain points in World coordinates.
  1071.  
  1072. Given  a  unit-length  vector to be used  as  the Z axis of a coordinate
  1073. system,  the  arbitrary axis algorithm  generates a corresponding X axis
  1074. for  the  coor- dinate system. The Y  axis follows by application of the
  1075. right hand rule.
  1076.  
  1077. The  method  is  to  examine the given  Z  axis  (also called the normal
  1078. vector) and see if it is close to the positive or negative World Z axis.
  1079. If  it is, cross the World Y axis with the given Z axis to arrive at the
  1080. arbitrary  X axis. If not, cross the World  Z axis with the given Z axis
  1081. to arrive at the arbitrary X axis. The boundary at which the decision is
  1082. made  was  chosen  to be both  inexpensive  to  calculate and completely
  1083. portable  across machines. This is achieved by having a sort of "square"
  1084. polar  cap, the bounds of which  is 1/64, which is precisely specifiable
  1085. in 6 decimal frac- tion digits and in 6 binary fraction bits.
  1086.  
  1087. In  mathematical terms, the algorithm  does the following (all "vectors"
  1088. are  assumed  to  be  in 3D  space,  specified  in  the World Coordinate
  1089. System).
  1090.  
  1091.     Let the given normal vector be called N.
  1092.     Let the World Y axis be called Wy, which is always (0,1,0).
  1093.     Let the World Z axis be called Wz, which is always (0,0,1).
  1094.  
  1095.                                                                          19
  1096.  AutoCAD Reference Manual
  1097.  
  1098. We are looking for the arbitrary X and Y axes to go with the normal N.
  1099. They'll be called Ax and Ay.  N could also be called Az (the arbitrary Z
  1100. axis).
  1101.  
  1102.     If (Nx < 1/64) and (Ny < 1/64) then
  1103.        Ax = Wy * N      (where "*" is the cross-product operator).
  1104.     Otherwise,
  1105.        Ax = Wz * N.
  1106.     Scale Ax to unit length.
  1107.  
  1108. The method of getting the Ay vector would be:
  1109.  
  1110.     Ay = N * Ax.
  1111.     Scale Ay to unit length.
  1112.  
  1113.  
  1114. C.1.6  Writing DXF Interface Programs
  1115.  
  1116. Writing  a program that communicates with  AutoCAD via the DXF mechanism
  1117. often  appears  far  more  difficult than  it  really  is.  The DXF file
  1118. contains a seemingly overwhelming amount of information, and examining a
  1119. DXF file manually may lead to the conclusion that the task is hopeless.
  1120.  
  1121. However,  the  DXF  file  has been designed  to  be  easy  to process by
  1122. program,  not  manually. The format  was constructed with the deliberate
  1123. intention  of making it easy to  ignore information you don't care about
  1124. while  easily reading the information you  need. Just remember to handle
  1125. the  groups in any order and ignore  any group you don't care about, and
  1126. you'll be home free.
  1127.  
  1128. As  an example, the following is a  Microsoft BASIC program that reads a
  1129. DXF  file and extracts all the  LINE entities from the drawing (ignoring
  1130. lines that appear inside Blocks). It prints the endpoints of these lines
  1131. on  the screen. As an exercise you  might try entering this program into
  1132. your  com-  puter, running it on a  DXF  file from one of your drawings,
  1133. then enhancing it to print the center point and radius of any circles it
  1134. encounters.  This  program  is not put  forward  as  an example of clean
  1135. programming  technique  nor  the way a  general  DXF processor should be
  1136. written;  it is presented as an example of just how simple a DXF-reading
  1137. program can be.
  1138.  
  1139.     1000 REM
  1140.     1010 REM Extract lines from DXF file
  1141.     1020 REM
  1142.     1030 G1% = 0
  1143.     1040 LINE INPUT "DXF file name: "; A$
  1144.     1050 OPEN "i", 1, A$ + ".dxf"
  1145.     1060 REM
  1146.     1070 REM Ignore until section start encountered
  1147.     1080 REM
  1148.     1090 GOSUB 2000
  1149.     1100 IF G% <> 0 THEN 1090
  1150.     1110 IF S$ <> "SECTION" THEN 1090
  1151.  
  1152.  
  1153. 20
  1154.                                     (C) Drawing Interchange and File Formats
  1155.  
  1156.     1120 GOSUB 2000
  1157.     1130 REM
  1158.     1140 REM Skip unless ENTITIES section
  1159.     1150 REM
  1160.     1160 IF S$ <> "ENTITIES" THEN 1090
  1161.     1170 REM
  1162.     1180 REM Scan until end of section, processing LINEs
  1163.     1190 REM
  1164.     1200 GOSUB 2000
  1165.     1210 IF G% = 0 AND S$ = "ENDSEC" THEN 2200
  1166.     1220 IF G% = 0 AND S$ = "LINE" THEN GOSUB 1400 : GOTO 1210
  1167.     1230 GOTO 1200
  1168.     1400 REM
  1169.     1410 REM Accumulate LINE entity groups
  1170.     1420 REM
  1171.     1430 GOSUB 2000
  1172.     1440 IF G% = 10 THEN X1 = X : Y1 = Y : Z1 = Z
  1173.     1450 IF G% = 11 THEN X2 = X : Y2 = Y : Z2 = Z
  1174.     1460 IF G% = 0 THEN PRINT "Line from (";X1;",";Y1;",";Z1;") to (";X2;
  1175.                               ",";Y2;",";Z2;")
  1176.     1470 GOTO 1430
  1177.     2000 REM
  1178.     2010 REM Read group code and following value
  1179.     2020 REM For X coordinates, read Y and possibly Z also
  1180.     2030 REM
  1181.     2040 IF G1% < 0 THEN G% = -G1% : G1% = 0 ELSE INPUT #1, G%
  1182.     2050 IF G% <   10 OR  G% =  999 THEN LINE INPUT #1, S$ : RETURN
  1183.     2060 IF G% >=  38 AND G% <=  49 THEN INPUT #1, V : RETURN
  1184.     2080 IF G% >=  50 AND G% <=  59 THEN INPUT #1, A : RETURN
  1185.     2090 IF G% >=  60 AND G% <=  69 THEN INPUT #1, P% : RETURN
  1186.     2100 IF G% >=  70 AND G% <=  79 THEN INPUT #1, F% : RETURN
  1187.     2110 IF G% >= 210 AND G% <= 219 THEN 2130
  1188.     2120 IF G% >=  20 THEN PRINT "Invalid group code";G% : STOP
  1189.     2130 INPUT #1, X
  1190.     2140 INPUT #1, G1%
  1191.     2150 IF G1% <> (G%+10) THEN PRINT "Invalid Y coord code";G1% : STOP
  1192.     2160 INPUT #1, Y
  1193.     2170 INPUT #1, G1%
  1194.     2180 IF G1% <> (G%+20) THEN G1% = -G1% ELSE INPUT #1, Z
  1195.     2190 RETURN
  1196.     2200 CLOSE 1
  1197.  
  1198. Writing  a program that constructs a DXF file is more difficult, because
  1199. you must maintain consistency within the drawing in order for AutoCAD to
  1200. find  it acceptable. AutoCAD allows you to omit many items in a DXF file
  1201. and  still  obtain  a usable drawing.  The  entire HEADER section can be
  1202. omitted if you don't need to set any header variables. Any of the tables
  1203. in  the  TABLES  section can be omitted  if  you  don't need to make any
  1204. entries, and in fact the entire TABLES section can be dropped if nothing
  1205. in  it is required. If you define any linetypes in the LTYPE table, this
  1206. table  must  appear before the LAYER  table. If no Block Definitions are
  1207. used  in  the  drawing, the BLOCKS  section  can be omitted. If present,
  1208. however, it must appear before the ENTITIES section. Within the ENTITIES
  1209. section, you can refer- ence layer names even though you haven't defined
  1210. them in the LAYER table.
  1211.  
  1212.                                                                         21
  1213. AutoCAD Reference Manual
  1214.  
  1215. Such  layers  will  be  automatically  created  with  color  7  and  the
  1216. CONTINUOUS linetype. The EOF item must be present at the end of file.
  1217.  
  1218. The following Microsoft BASIC program constructs a DXF file representing
  1219. a  polygon with a specified number  of sides, leftmost origin point, and
  1220. side  length. This program supplies only the ENTITIES section of the DXF
  1221. file,  and places all entities generated  on the default layer "0". This
  1222. may  be  taken as an example of  a minimum DXF generation program. Since
  1223. this  pro-  gram doesn't create the  drawing header, the drawing limits,
  1224. extents,  and  current view will be  invalid after performing a DXFIN on
  1225. the  drawing gener- ated by this program. You  can do a "ZOOM E" to fill
  1226. the screen with the drawing generated. Then adjust the limits manually.
  1227.  
  1228.     1000 REM
  1229.     1010 REM Polygon generator
  1230.     1020 REM
  1231.     1030 LINE INPUT "Drawing (DXF) file name: "; A$
  1232.     1040 OPEN "o", 1, A$ + ".dxf"
  1233.     1050 PRINT #1, 0
  1234.     1060 PRINT #1, "SECTION"
  1235.     1070 PRINT #1, 2
  1236.     1080 PRINT #1, "ENTITIES"
  1237.     1090 PI = ATN(1) * 4
  1238.     1100 INPUT "Number of sides for polygon: "; S%
  1239.     1110 INPUT "Starting point (X,Y): "; X, Y
  1240.     1120 INPUT "Polygon side: "; D
  1241.     1130 A1 = (2 * PI) / S%
  1242.     1140 A = PI / 2
  1243.     1150 FOR I% = 1 TO S%
  1244.     1160 PRINT #1, 0
  1245.     1170 PRINT #1, "LINE"
  1246.     1180 PRINT #1, 8
  1247.     1190 PRINT #1, "0"
  1248.     1200 PRINT #1, 10
  1249.     1210 PRINT #1, X
  1250.     1220 PRINT #1, 20
  1251.     1230 PRINT #1, Y
  1252.     1240 PRINT #1, 30
  1253.     1250 PRINT #1, 0.0
  1254.     1260 NX = D * COS(A) + X
  1255.     1270 NY = D * SIN(A) + Y
  1256.     1280 PRINT #1, 11
  1257.     1290 PRINT #1, NX
  1258.     1300 PRINT #1, 21
  1259.     1310 PRINT #1, NY
  1260.     1320 PRINT #1, 31
  1261.     1330 PRINT #1, 0.0
  1262.     1340 X = NX
  1263.     1350 Y = NY
  1264.     1360 A = A + A1
  1265.     1370 NEXT I%
  1266.     1380 PRINT #1, 0
  1267.     1390 PRINT #1, "ENDSEC"
  1268.  
  1269. 22
  1270.                                     (C) Drawing Interchange and File Formats
  1271.  
  1272.     1400 PRINT #1, 0
  1273.     1410 PRINT #1, "EOF"
  1274.     1420 CLOSE 1
  1275.  
  1276. The  DXFIN command is relatively forgiving with respect to the format of
  1277. data  items. As long as a properly formatted item appears on the line on
  1278. which  the  data  is expected, DXFIN  will  accept it (of course, string
  1279. items  should  not have leading spaces  unless  these are intended to be
  1280. part  of  the  string).  The  above  program  takes  advantage  of  this
  1281. flexibility in input format, and does not go to great effort to generate
  1282. a file appearing exactly like one generated by AutoCAD.
  1283.  
  1284. In the case of error loading a DXF file using DXFIN, AutoCAD reports the
  1285. error with a message indicating the nature of the error detected and the
  1286. last  line processed in the DXF file before the error was detected. This
  1287. may  not be the line on which the error occurred, especially in the case
  1288. of such errors as omission of required groups.
  1289.  
  1290.  
  1291.  
  1292. C.2 Binary Drawing Interchange Files
  1293.  
  1294. The  ASCII  DXF file format described  in the preceding sections of this
  1295. appendix  is a complete representation of an AutoCAD drawing in an ASCII
  1296. text  form easily processed by other  programs. In addition, AutoCAD can
  1297. produce  or read a binary form of the full DXF file, and accepts limited
  1298. input in another binary file format. These binary files are described in
  1299. the following sections.
  1300.  
  1301.  
  1302. C.2.1  Binary DXF Files
  1303.  
  1304. The  DXFOUT  command provides a "Binary"  option  that writes binary DXF
  1305. files.  Such a file contains all of  the information present in an ASCII
  1306. DXF  file,  but in a much more  compact  form that takes, typically, 25%
  1307. less  file  space and can be read  and written more quickly (typically 5
  1308. times  faster)  by  AutoCAD.  Unlike ASCII  DXF  files,  which  entail a
  1309. trade-off  between  size and floating-point  accuracy,  binary DXF files
  1310. preserve all of the accuracy in the drawing database. AutoCAD Release 10
  1311. is the first version to support this form of DXF file; it cannot be read
  1312. by older versions.
  1313.  
  1314. A binary DXF file begins with a 22-byte sentinel consisting of:
  1315.  
  1316.     "AutoCAD Binary DXF<CR><LF><SUB><NUL>"
  1317.  
  1318. Following the sentinel are (group,value) pairs as in an ASCII DXF file, but
  1319. represented in binary form.  The group code is a single-byte binary value,
  1320. and the value that follows is one of the following:
  1321.  
  1322.   o  a two-byte integer with the least significant byte first and the
  1323.      most significant byte last,
  1324.  
  1325.  
  1326.  
  1327.                                                                          23
  1328.  AutoCAD Reference Manual
  1329.  
  1330.   o  an eight-byte IEEE double precision floating-point number stored
  1331.      with the least significant byte first and the most significant
  1332.      byte last, or
  1333.  
  1334.   o  an ASCII string terminated by a zero (NUL) byte.
  1335.  
  1336. The  type  of the datum following a  group  is determined from the group
  1337. code  according  to  the same rules  used  in  decoding ASCII DXF files.
  1338. Translation  of  angles to degrees, and  dates to fractional Julian date
  1339. representation,  is performed for binary files  as well as for ASCII DXF
  1340. files. The comment group, 999, is not used in binary DXF files.
  1341.  
  1342. DXFOUT  writes binary DXF files with the  same file type (".dxf") as for
  1343. ASCII  DXF  files. The DXFIN  command  automatically recognizes a binary
  1344. file  (by  means of its sentinel string)  and loads it. There is no need
  1345. for you to identify it as a binary file.
  1346.  
  1347. If  DXFIN encounters an error in a  binary DXF file, it reports the byte
  1348. address within the file where the error was detected.
  1349.  
  1350.  
  1351. C.3  Binary Drawing Interchange (DXB) Files
  1352.  
  1353. The  DXF  file formats described earlier  in  this appendix are complete
  1354. repre-  sentations of an AutoCAD drawing that can be written and read by
  1355. AutoCAD and other programs. However, AutoShade(tm) and programs executed
  1356. via  the "external commands" facility (Appendix  B) often have a need to
  1357. supply  simple  geometric input to  AutoCAD. For these purposes, another
  1358. file  format even more compact than  the binary DXF format is supported.
  1359. This format, called DXB (for "drawing interchange binary") is limited in
  1360. the  entities  it can represent. Furthermore,  AutoCAD  has a command to
  1361. read  such files, but no direct method of writing them. (The ADI plotter
  1362. driver can plot to a file in DXB format.)
  1363.  
  1364.  
  1365. C.3.1  DXBIN Command
  1366.  
  1367. To load a DXB file produced by a program such as AutoShade, enter the DXBIN
  1368. command:
  1369.  
  1370.     Command:  DXBIN
  1371.     DXB file:
  1372.  
  1373. enter  the name of the file you wish to load. Don't include a file type;
  1374. ".dxb" is assumed.
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384. 24
  1385.                                     (C) Drawing Interchange and File Formats
  1386.  
  1387. C.3.2  DXB File Format
  1388.  
  1389. This information is for experienced programmers, and is subject to change
  1390. without notice.
  1391.  
  1392. The format of a DXB file is as follows:
  1393.  
  1394.     Header:      "AutoCAD DXB 1.0" CR LF ^Z NUL       (19 bytes)
  1395.     Data:      . . . Zero or more data records . . .
  1396.     Terminator:  NUL                                  (1 byte)
  1397.  
  1398. Each  data record begins with a single byte giving its type, followed by
  1399. data  items.  Th